#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int ret = fork();
if(ret < 0){
perror("fork");
return 1;
}
else if(ret == 0){ //child
while(1)
{
sleep(1);
printf("I am child : %d, myfather: %d\n", getpid(), getppid());
}
}else{ //father
while(1)
{
sleep(1);
printf("I id : %d, myfather id: %d\n", getpid(), getppid());
}
}
printf("进程开始： : %d\n",getpid());
return 0;
}
